﻿package frEngine.primitives.lightingline.bullet
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import flash.geom.*;
    import frEngine.core.mesh.*;
    import frEngine.primitives.lightingline.*;

    public class GeometryLighting extends FrFlashLine
    {
        private var _beginOffset:Number = 0;
        private var _startStatic:Vector3D;
        private var _endStatic:Vector3D;
        public var hangStart:Boolean = false;
        public var startHangObjUid:String;
        public var startHangBoneName:String;
        public var startHangTemple:Boolean;
        public var startHangObj:Pivot3D;
        public var hangEnd:Boolean = false;
        public var endHangObjUid:String;
        public var endHangBoneName:String;
        public var endHangTemple:Boolean;
        public var endHangObj:Pivot3D;
        private var _start:Vector3D;
        private var _end:Vector3D;
        private var _singleLine:NoiseLine;

        public function GeometryLighting(param1:String)
        {
            this._startStatic = new Vector3D();
            this._endStatic = new Vector3D();
            this._start = new Vector3D();
            this._end = new Vector3D();
            super(param1, true, null);
            this._singleLine = new NoiseLine(this._start, this._end);
            var _loc_2:* = new Vector.<NoiseLine>;
            _loc_2.push(this._singleLine);
            this.SetLines(_loc_2);
            return;
        }// end function

        override public function update(param1:int = 0) : void
        {
            super.update(param1);
            if (_escapeTime == 0)
            {
                return;
            }
            if (this.hangStart)
            {
                this.updateStartPoint();
            }
            if (this.hangEnd)
            {
                this.updateEndPoint();
            }
            return;
        }// end function

        public function freshPoints() : void
        {
            if (this.hangStart)
            {
                this.updateStartPoint();
            }
            if (this.hangEnd)
            {
                this.updateEndPoint();
            }
            return;
        }// end function

        private function getHangBoneAndUid(param1:String) : Array
        {
            if (!param1)
            {
                param1 = "";
            }
            var _loc_2:* = param1.split("||");
            _loc_2.length = 3;
            var _loc_3:* = _loc_2[0];
            var _loc_4:* = _loc_2[1];
            return [_loc_4, _loc_3];
        }// end function

        public function set startHangString(param1:String) : void
        {
            var _loc_2:* = this.getHangBoneAndUid(param1);
            this.startHangObjUid = _loc_2[1];
            this.startHangBoneName = _loc_2[0];
            return;
        }// end function

        public function set endHangString(param1:String) : void
        {
            var _loc_2:* = this.getHangBoneAndUid(param1);
            this.endHangObjUid = _loc_2[1];
            this.endHangBoneName = _loc_2[0];
            return;
        }// end function

        public function get startStatic() : Vector3D
        {
            return this._startStatic;
        }// end function

        public function set startStatic(param1:Vector3D) : void
        {
            this._startStatic = param1;
            this._start.x = this._startStatic.x;
            this._start.y = this._startStatic.y;
            this._start.z = this._startStatic.z;
            return;
        }// end function

        public function get endStatic() : Vector3D
        {
            return this._endStatic;
        }// end function

        public function set endStatic(param1:Vector3D) : void
        {
            this._endStatic = param1;
            this._end.x = this._endStatic.x;
            this._end.y = this._endStatic.y;
            this._end.z = this._endStatic.z;
            return;
        }// end function

        private function getPos(param1:Md5Mesh, param2:String = "Bip001 Pelvis") : Vector3D
        {
            var _loc_3:Vector3D = null;
            var _loc_4:Vector3D = null;
            var _loc_5:Vector3D = null;
            if (param2)
            {
                _loc_4 = param1.targetMd5Controler.getGJointPoseByName(param2);
                if (_loc_4)
                {
                    _loc_3 = param1.world.transformVector(_loc_4);
                }
                else
                {
                    param2 = null;
                }
            }
            if (!param2)
            {
                _loc_5 = new Vector3D();
                param1.world.copyColumnTo(3, _loc_5);
                _loc_3 = _loc_5;
            }
            return _loc_3;
        }// end function

        private function updateStartPoint() : void
        {
            var _loc_1:Vector3D = null;
            if (this.startHangObj)
            {
                if (this.startHangObj is Md5Mesh)
                {
                    _loc_1 = this.getPos(Md5Mesh(this.startHangObj), this.startHangBoneName);
                }
                else
                {
                    _loc_1 = this.startHangObj.getPosition(false);
                }
            }
            if (_loc_1)
            {
                this._start.x = _loc_1.x;
                this._start.y = _loc_1.y;
                this._start.z = _loc_1.z;
            }
            return;
        }// end function

        private function updateEndPoint() : void
        {
            var _loc_1:Vector3D = null;
            if (this.endHangObj)
            {
                if (this.endHangObj is Md5Mesh)
                {
                    _loc_1 = this.getPos(Md5Mesh(this.endHangObj), this.endHangBoneName);
                }
                else
                {
                    _loc_1 = this.endHangObj.getPosition(false);
                }
            }
            if (_loc_1)
            {
                this._end.x = _loc_1.x;
                this._end.y = _loc_1.y;
                this._end.z = _loc_1.z;
            }
            return;
        }// end function

        public function get beginOffset() : Number
        {
            return this._beginOffset;
        }// end function

        public function set beginOffset(param1:Number) : void
        {
            this._beginOffset = param1;
            this._singleLine.beginOffset = this._beginOffset;
            return;
        }// end function

    }
}
